package ThreadPool.creatpool.createMethod1.MyCallableTest;
import java.util.concurrent.*;
public class CreatThreadPool2 {
    public static void main(String[] args)
    {
        ThreadPoolExecutor tpe = new ThreadPoolExecutor(3,//核心线程数
                5,//最大线程数
                10,//临时线程存活时间
                TimeUnit.SECONDS,//时间单位
                new ArrayBlockingQueue<Runnable>(5),//阻塞队列
                Executors.defaultThreadFactory(),//线程工厂
                new ThreadPoolExecutor.CallerRunsPolicy()//拒绝策略
        );
        Future<String> f1 = tpe.submit(new MyCallable(100));
        Future<String> f2 = tpe.submit(new MyCallable(200));
        Future<String> f3 = tpe.submit(new MyCallable(300));
        Future<String> f4 = tpe.submit(new MyCallable(400));

        try {
            System.out.println(f1.get());
            System.out.println(f2.get());
            System.out.println(f3.get());
            System.out.println(f4.get());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
